package com.us.usws.site.ws.entity.video;

import java.util.ArrayList;
import java.util.List;

import com.us.usws.biz.WSResourceURIReplacer;
import com.us.usws.model.domain.video.Video;
import com.us.usws.model.domain.video.VideoComment;
import com.us.usws.site.ws.entity.WSEntity;
import com.us.usws.site.ws.entity.WSEntityFactory;
import com.us.usws.site.ws.entity.video.videocomment.WSVideoCommentDetail;
import com.us.usws.site.ws.entity.video.videocomment.WSVideoComments;
import com.us.usws.site.ws.entity.video.videoinfo.WSVideoInfoVideo;
import com.us.usws.support.uitls.SimpleDataPageUtil;

public class WSVideoEntityPackGenerator {

	private static WSVideoEntityPackGenerator instance = new WSVideoEntityPackGenerator();

	private WSVideoEntityPackGenerator() {
	}

	public static WSVideoEntityPackGenerator getInstance() {
		return instance;
	}

	/**
	 * get video info
	 * @param video
	 * @return
	 */
	public WSEntity getVideoInfoVideoPack(Video video) {
		if (video == null) {
			return WSEntityFactory.getEmptyEntityWithRecords();
		}

		//prepare util classes
		WSVideoInfoVideo data = PackEntityConverter.genWSVideoInfoVideo(video);

		//pack data
		WSEntity ret = WSEntityFactory.getDefaultWSEntity(data);
		return ret;

	}

	/**
	 * get video comment pack
	 * @param videoUid
	 * @param results
	 * @param pu
	 * @return
	 */
	public WSEntity getVideoCommentsPack(String videoUid, List<VideoComment> comments, SimpleDataPageUtil pu) {
		if (comments == null) {
			return WSEntityFactory.getEmptyEntityWithRecords();
		}

		//prepare util classes
		WSVideoComments data = new WSVideoComments();
		data.setPrevPageUrl(WSResourceURIReplacer.getVideoCommentListURLWithPageNo(videoUid, pu.getPageNo() - 1, pu.getPageCount()));
		data.setNextPageUrl(WSResourceURIReplacer.getVideoCommentListURLWithPageNo(videoUid, pu.getPageNo() + 1, pu.getPageCount()));
		data.setPageCnt(pu.getPageCount());
		data.setPageNo(pu.getPageNo());
		data.setPageSize(pu.getPageSize());
		data.setTotalCommentsCnt(pu.getRowCount());

		List<WSVideoCommentDetail> records = new ArrayList<WSVideoCommentDetail>(comments.size());
		//loop for channels
		for (VideoComment eachC : comments) {
			//convert to WS entity
			//WSChannelVideoDetail vd = PackEntityConverter.g
			WSVideoCommentDetail vd = PackEntityConverter.genWSVideoCommentDetail(eachC);

			//add one channel to data
			records.add(vd);
		}

		data.setRecords(records);

		//pack data
		WSEntity ret = WSEntityFactory.getDefaultWSEntity(data);
		return ret;
	}

}
